package com.dqyt.app.controller;

import com.alibaba.fastjson.JSON;
import com.dqyt.app.service.SampleService;
import com.dqyt.khjc.bean.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 样品控制器
 */
@RestController
public class SampleController {

    /**
     * 样品操作类
     */
    @Autowired
    private SampleService mSampleService;

    /**
     * 查询样品列表信息分页
     *
     * @param request
     * @param addTime
     * @param type
     * @param bsbh
     * @param
     * @return
     */
    @RequestMapping("/sample/getSampleInfos")
    public String getSampleInfos(HttpServletRequest request,Integer page,Integer size, long userId, String token,
                                 long addTime, int type, String bsbh, String erweima,long wtfId,int sampleStatue) {
        return JSON.toJSONString(mSampleService.getSampleInfos(request, page,size,userId, token, addTime, type, bsbh, erweima,wtfId,sampleStatue));
    }

    /**
     * 查询样品信息
     *
     * @param request
     * @param userId
     * @param token
     * @param type
     * @param bsbh
     * @param erweima
     * @return
     */
    @RequestMapping("/sample/getSample")
    public String getSample(HttpServletRequest request, long userId, String token, int type, String bsbh, String erweima,String sbbh) {
        return JSON.toJSONString(mSampleService.getSample(request, userId, token, type, bsbh, erweima,sbbh));
    }



    /**
     * 扫描二维码查询样品信息
     *
     * @param request
     * @param userId
     * @param token
     * @param erweima
     * @return
     */
    @RequestMapping("/sample/getSampleByQrcode")
    public String getSampleByQrcode(HttpServletRequest request, long userId, String token, String erweima) {
        return JSON.toJSONString(mSampleService.getSampleByQrcode(request, userId, token,erweima));
    }


    /**
     * 查询样品信息
     *
     * @param request
     * @param userId
     * @param token
     * @param type
     * @param
     * @param
     * @return
     */
    @RequestMapping("/sample/getSampleBysbbh")
    public String getSampleBysbbh(HttpServletRequest request, long userId, String token, int type, String sbbh) {
        return JSON.toJSONString(mSampleService.getSampleBysbbh(request, userId, token, type,sbbh));
    }


    /**
     * 查询匹配 气瓶信息
     *
     * @param request
     * @param userId
     * @param token
     * @param
     * @param
     * @return
     */
    @RequestMapping("/sample/getCylindersBysbbh")
    public String getCylindersBysbbh(HttpServletRequest request, long userId, String token, String bsbh) {
        return JSON.toJSONString(mSampleService.getCylindersBysbbh(request, userId, token, bsbh));
    }



    /**
     * 新增样品信息
     *
     * @param request
     * @param userId
     * @param token
     * @param sample
     * @return
     */
    @RequestMapping("/sample/addSample")
    public String addSample(HttpServletRequest request, long userId, String token, String sample) {
        return JSON.toJSONString(mSampleService.addSample(request, userId, token, sample));
    }

    /**
     * 更新样品信息
     *
     * @param request
     * @param userId
     * @param token
     * @param sample
     * @return
     */
    @RequestMapping("/sample/updateSample")
    public String updateSample(HttpServletRequest request, long userId, String token, String sample) {
        return JSON.toJSONString(mSampleService.updateSample(request, userId, token, sample));
    }


    /**
     * 查询为分配的 任务的 样品
     * @param bsbh   标识编号
     * @param type  样品类型  1：呼吸器  2: 复合气瓶
     * @return
     */
    @RequestMapping(value = "/sample/getSampleListWorkAll")
    public ResultMsg getSampleListWorkAll(HttpServletRequest request,long userId, String token,
                                          @RequestParam(name = "bsbh", required = false, defaultValue = "")  String bsbh,
                                          @RequestParam(defaultValue = "0")Integer type){
        ResultMsg resultMsg = mSampleService.getSampleListWorkAll(request,userId,token, bsbh, type);
        return resultMsg;
    }








    /**
     * 分配任务
     * @return
     */
    @RequestMapping(value = "/sample/assignTasks")
    public ResultMsg assignTasks(HttpServletRequest request,long userId, String token,String  bsbhArrar,String jcrUserId,String jcrStr){
        ResultMsg resultMsg = mSampleService.assignTasks(request,userId,token, bsbhArrar, jcrUserId,jcrStr);
        return resultMsg;
    }

}
